package org.dromara.germbank.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.constant.SystemConstants;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.germbank.domain.BusPartnerClinic;
import org.dromara.germbank.domain.bo.BusPartnerClinicBo;
import org.dromara.germbank.domain.vo.BusPartnerClinicVo;
import org.dromara.germbank.mapper.BusPartnerClinicMapper;
import org.dromara.germbank.service.BusPartnerClinicService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 合作诊所 实现类
 *
 * @author congxing
 */

@Slf4j
@RequiredArgsConstructor
@Service
public class BusPartnerClinicsServiceImpl implements BusPartnerClinicService {

    private final BusPartnerClinicMapper busPartnerClinicMapper;

    @Override
    public TableDataInfo<BusPartnerClinicVo> queryPageList(BusPartnerClinicBo bo, PageQuery pageQuery) {

        Page<BusPartnerClinicVo> page = busPartnerClinicMapper.queryPageList(pageQuery.build(),this.buildQueryWrapper(bo));
        return TableDataInfo.build(page);
    }

    @Override
    public boolean checkClinicNameUnique(BusPartnerClinicBo bo) {
        return false;
    }

    @Override
    public int insertClinic(BusPartnerClinicBo bo) {
        return 0;
    }

    @Override
    public void updateClinicData(BusPartnerClinicBo bo) {

    }

    @Override
    public void deleteClinicDataByIds(List<Long> bo) {

    }


    // 分页查询条件
    private Wrapper<BusPartnerClinic> buildQueryWrapper(BusPartnerClinicBo bo) {
        return Wrappers.<BusPartnerClinic>lambdaQuery()
            // 逻辑删除字段（固定条件）
            .eq(BusPartnerClinic::getDelFlag, SystemConstants.NORMAL)

            // 诊所名称（模糊）
            .like(StringUtils.isNotBlank(bo.getClinicName()),
                BusPartnerClinic::getClinicName, bo.getClinicName())

            // 完整地址（模糊）
            .like(StringUtils.isNotBlank(bo.getClinicAddress()),
                BusPartnerClinic::getClinicAddress, bo.getClinicAddress())

            // 合作状态（精确）
            .eq(StringUtils.isNotBlank(bo.getCoopStatus()),
                BusPartnerClinic::getCoopStatus, bo.getCoopStatus())

            // 前端可见性（精确）
            .eq(StringUtils.isNotBlank(bo.getDisplayStatus()),
                BusPartnerClinic::getDisplayStatus, bo.getDisplayStatus())

            // 排序
            .orderByAsc(BusPartnerClinic::getId);
    }
}
